package com.hao.vertx.web.entity;

import io.vertx.sqlclient.templates.RowMapper;

import java.io.Serializable;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class Order implements Serializable {

    private Long id;
    private String name;
    private String userName;
    private String createTime;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public static class OrderRowMapper{
        final ZoneOffset zoneOffset = ZoneOffset.of("+8");
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        public RowMapper<Order> getRowMapper(){
            RowMapper<Order> rowMapper = row -> {
                Order order = new Order();
                order.setId(row.getLong("id"));
                order.setName(row.getString("name"));
                order.setUserName(row.getString("user_name"));
                order.setCreateTime(row.getOffsetDateTime("create_time").toInstant().atOffset(zoneOffset).format(formatter));
                return order;
            };
            return rowMapper;
        }
    }
}
